package l1j.server.server.datatables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import l1j.server.L1DatabaseFactory;
import l1j.server.server.utils.SQLUtil;
import l1j.server.server.utils.collections.Maps;

public class MotionCommandsTable {
	private static MotionCommandsTable _instance = new MotionCommandsTable();

	public static MotionCommandsTable getInstance() {
		return _instance;
	}

	public static void initilize() {
		_instance = new MotionCommandsTable();
	}

	private Map<Integer, AllMotionCommands> _allCommands_String = Maps.newMap();

	private MotionCommandsTable() {
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con.prepareStatement("SELECT * FROM x_motion_commands");

			rs = pstm.executeQuery();
			while (rs.next()) {
				AllMotionCommands mc = new AllMotionCommands();
				mc.setId(rs.getInt("id"));
				mc.setCommand_en(rs.getString("command_en"));
				mc.setCommand_ch(rs.getString("command_ch"));
				mc.setSingle_string_1(rs.getString("single_string_1"));
				mc.setSingle_string_2(rs.getString("single_string_2"));
				mc.setPair_string_1(rs.getString("pair_string_1"));
				mc.setPair_string_2(rs.getString("pair_string_2"));
				mc.setPair_string_3(rs.getString("pair_string_3"));
				_allCommands_String.put(rs.getInt("id"), mc);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}
	
	public Map<Integer, AllMotionCommands> getAllCommands() {
		return _allCommands_String;
	}

	public class AllMotionCommands {
		private int id = 0;
		private String command_en = "";
		private String command_ch = "";
		private String single_string_1 = "";
		private String single_string_2 = "";
		private String pair_string_1 = "";
		private String pair_string_2 = "";
		private String pair_string_3 = "";

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getCommand_en() {
			return command_en;
		}

		public void setCommand_en(String command_en) {
			this.command_en = command_en;
		}

		public String getCommand_ch() {
			return command_ch;
		}

		public void setCommand_ch(String command_ch) {
			this.command_ch = command_ch;
		}

		public String getSingle_string_1() {
			return single_string_1;
		}

		public void setSingle_string_1(String single_string_1) {
			this.single_string_1 = single_string_1;
		}

		public String getSingle_string_2() {
			return single_string_2;
		}

		public void setSingle_string_2(String single_string_2) {
			this.single_string_2 = single_string_2;
		}

		public String getPair_string_1() {
			return pair_string_1;
		}

		public void setPair_string_1(String pair_string_1) {
			this.pair_string_1 = pair_string_1;
		}

		public String getPair_string_2() {
			return pair_string_2;
		}

		public void setPair_string_2(String pair_string_2) {
			this.pair_string_2 = pair_string_2;
		}

		public String getPair_string_3() {
			return pair_string_3;
		}

		public void setPair_string_3(String pair_string_3) {
			this.pair_string_3 = pair_string_3;
		}
	}
}